package com.example.kaoqinmanager.activity;


import android.content.DialogInterface;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;

import com.example.kaoqinmanager.R;
import com.example.kaoqinmanager.base.BaseBindingActivity;
import com.example.kaoqinmanager.databinding.ActivitySettingBinding;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

public class SettingActivity extends BaseBindingActivity<ActivitySettingBinding> {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        actionBar.setTitle("设置");
        //显示返回箭头默认是不显示的
        actionBar.setDisplayHomeAsUpEnabled(true);

        if (mSharePreferenceUtil.getUserRole() == 1) {
            getBinding().tvSet.setVisibility(View.VISIBLE);
        } else {
            getBinding().tvSet.setVisibility(View.INVISIBLE);
        }

        getBinding().tvSignOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                new MaterialAlertDialogBuilder(mActivity)
                        .setTitle(getString(R.string.text_tip))
                        .setMessage(getString(R.string.text_signout))
                        .setNegativeButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                mSharePreferenceUtil.setIsLogin(false);
                                openActivity(LoginActivity.class);
                                exit();
                            }
                        })
                        .setPositiveButton("取消", null)
                        .show();


            }
        });
        getBinding().tvSet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openActivity(PaiBanSetActivity.class);
            }
        });
        getBinding().tvUpdatepass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openActivity(UpdatePasswordActivity.class);
            }
        });

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            //actionbar的左侧图标的点击事件处理
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}

